package com.edgar.baselibrary.network.response;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.edgar.baselibrary.network.MessageCode;

/**
 * Created by edgar on 2016/1/22.
 */
public class VolleyDelegateResponse implements Response.Listener<String>,Response.ErrorListener{

    private IResponse<?> mClientResponse;

    public <T> void setClientResponse(IResponse<T> response){
        this.mClientResponse = response;
    }

    @Override
    public void onErrorResponse(VolleyError error) {
        if(mClientResponse != null){
            mClientResponse.processError(MessageCode.getResponseErrorByVolleyError(error));
        }
    }

    @Override
    public void onResponse(String response) {
        if(mClientResponse != null){
            mClientResponse.processResponse(response);
        }
    }
}